<?php

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

class CreateTenantAuthenticationTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    addCustomColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Any other destructive changes will result in an error when trying to
     * rollback the migration.
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('tenant_authentication', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '租户认证表']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '租户认证ID'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '所属租户id'])
            ->addColumn('company_name', 'string', ['default' => '', 'limit' => 255, 'comment' => '公司名称'])
            ->addColumn('unified_social_credit_code', 'char', ['default' => '', 'limit' => 20, 'comment' => '统一社会信用代码'])
            ->addColumn('company_registered_address', 'string', ['default' => '', 'limit' => 255, 'comment' => '公司注册地址'])
            ->addColumn('company_business_scope', 'text', ['null' => true, 'comment' => '公司经营范围'])
            ->addColumn('operation_period_end', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '经营期限(止), 0为长期'])
            ->addColumn('bank_of_deposit', 'string', ['default' => '', 'limit' => 128, 'comment' => '开户银行'])
            ->addColumn('bank_subbranch', 'string', ['default' => '', 'limit' => 128, 'comment' => '开户支行'])
            ->addColumn('bank_account', 'char', ['default' => '', 'limit' => 24, 'comment' => '银行账户'])
            ->addColumn('bank_account_owner', 'string', ['default' => '', 'limit' => 128, 'comment' => '开户人'])
            ->addColumn('legal_person_name', 'string', ['default' => '', 'limit' => 128, 'comment' => '法人姓名'])
            ->addColumn('legal_id_number', 'char', ['default' => '', 'limit' => 18, 'comment' => '法人身份证号码'])
            ->addColumn('legal_phone', 'char', ['default' => '', 'limit' => 20, 'comment' => '法人手机号码'])
            ->addColumn('legal_id_period_end', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '法人身份证有效期限(止), 0为长期'])
            ->addColumn('company_web_site', 'string', ['default' => '', 'limit' => 255, 'comment' => '公司官网'])
            ->addColumn('company_office_address', 'string', ['default' => '', 'limit' => 255, 'comment' => '公司办公地址'])
            ->addColumn('person_in_charge', 'string', ['default' => '', 'limit' => 128, 'comment' => '公司主要负责人'])
            ->addColumn('person_in_charge_phone', 'char', ['default' => '', 'limit' => 20, 'comment' => '公司主要负责人手机号码'])
            ->addColumn('person_in_charge_email', 'string', ['default' => '', 'limit' => 128, 'comment' => '公司主要负责人邮箱'])
            ->addColumn('company_found_date', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '公司成立时间'])
            ->addColumn('company_staff_number', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '公司整体员工人数'])
            ->addColumn('company_manager_number', 'string', ['default' => "", 'null' => false, 'limit' => 40, 'comment' => '公司管理人员数量'])
            ->addColumn('company_maker_number', 'string', ['default' => "", 'null' => false, 'limit' => 40, 'comment' => '公司制作人员数量'])
            ->addColumn('service_category', 'json', ['null' => true, 'comment' => '服务类别'])
            ->addColumn('company_profile', 'text', ['null' => true, 'comment' => '公司简介'])
            ->addColumn('company_success_stories', 'string', ['default' => '', 'limit' => 255, 'comment' => '成功案例连接'])
            ->addColumn('company_demo_links', 'string', ['default' => '', 'limit' => 255, 'comment' => '作品连接'])
            ->addColumn('company_customer_service', 'json', ['null' => true, 'comment' => '曾服务客户'])
            ->addColumn('office_hardware', 'char', ['default' => '', 'limit' => 20, 'comment' => '办公室硬件'])
            ->addColumn('secrecy_level', 'string', ['default' => '', 'limit' => 1024, 'comment' => '保密级别'])
            ->addColumn('reasons_for_failure', 'text', ['null' => true, 'comment' => '未通过理由，通过清空'])
            ->addColumn('status', 'enum', ['values' => 'submitting,to_be_reviewed,active,invalid', 'default' => 'submitting', 'comment' => '认证状态'])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新时间'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者'])
            ->addColumn('created', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => 'json字段，存储自定义字段'])
            ->addColumn('fdd_auth_status', 'integer', ['limit' => 2, 'default' => 0, 'comment' => 'FDD认证状态'])
            ->addColumn('fdd_transaction_no', 'string', ['default' => "", 'limit' => 255, 'null' => false, 'comment' => 'FDD实名认证的序列号'])
            ->addColumn('fdd_auth_url', 'text', ['null' => true, 'comment' => 'FDD实名认证URL'])
            ->addColumn('fdd_auth_status_desc', 'string', ['limit' => 2048, 'null' => false, 'default' => '', 'comment' => 'FDD实名认证状态文字结果'])
            ->addColumn('fdd_cert_status', 'integer', ['limit' => 1, 'default' => 0, 'comment' => 'FDD证书生成状态']);

        //执行创建
        $table->create();
    }
}
